﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IdentityModel.Selectors;
using WSIMCommons;
using WSIMServices.model;
using System.Data;
using System.Security;

namespace WSIMServices
{
    public class WSIMAuthentication: UserNamePasswordValidator
    {
        //TODO: qui non va bene deve essere accessibile anche da altri posti
        private static List<User> loggedIn = new List<User>();

        public override void Validate(string userName, string password)
        {            
            if (userName == "guest") return;

            //TODO: usare LINQ per interrogare la collection di utenti per caching

            WSIMProfilesTableAdapters.wsim_userTableAdapter users = new WSIMServices.WSIMProfilesTableAdapters.wsim_userTableAdapter();
            WSIMProfiles.wsim_userDataTable table = users.GetDataByCredentials(userName, WSIMCommons.WSIMUtilities.SHA2(password));
            if (table.Rows.Count == 0) throw new SecurityException(ErrorCodesEnum.W1002_ERROR_IN_AUTHENTICATION.ToString());


        }
    }
}
